<?php

function langEcho($string, $lang = '', $lower = false){
	if(!$lang){
		$lang =  getLanguage();
	}
	GLOBAL $LANG;
	$key = $string;
	if($lower){
		$key = strtolower($string);
	}
	if(array_key_exists($key, $LANG))
		return  $LANG[$key];

	return $string;
}

function getLanguage(){	
	if(isUserLoggedIn()){
		return $_SESSION["userlang"];
	}
	
	if(isset($_COOKIE['lang'])){
		return $_COOKIE['lang'];
	}
	
	return DEFAULTLANG;
}

function ParseDateTimeToEn($date){
	$size = strlen($date);
	$day = "";
	$month = "";
	$year = "";
	if (getLanguage() == "en"){
		return $date;
	}else if (getLanguage() == "es"){
		for($i = 0; $i<2; $i++){
			$day.= $date[$i];
		}
		for($i = 3; $i<5; $i++){
			$month.= $date[$i];
		}
		for($i = 6; $i<$size; $i++){
			$year.= $date[$i];
		}		
	}
	
	return $month . "/" . $day . "/" . $year;
}

function ParseDateTimeToEs($date){
	$size = strlen($date);
	$day = "";
	$month = "";
	$year = "";
	
	for($i = 0; $i<2; $i++){
		$month.= $date[$i];
	}
	for($i = 3; $i<5; $i++){
		$day.= $date[$i];
	}		
	for($i = 6; $i<$size; $i++){
		$year.= $date[$i];
	}		
	
	
	return $day . "/" . $month . "/" . $year;
}


?>